package com.liang.blog.system.listener;

import com.alibaba.excel.context.AnalysisContext;

import com.alibaba.excel.event.AnalysisEventListener;
import com.liang.blog.model.BlogDict;
import com.liang.blog.system.mapper.BlogDictMapper;
import com.liang.blog.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * easyExcel 读文件监听器
 * @Author：YanWenLiang
 * @Date:2023-05-27-18:56
 */
public class DictListener extends AnalysisEventListener<DictEeVo> {

    private BlogDictMapper dictMapper;

    public DictListener() {
    }

    public DictListener(BlogDictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    // 一行一行读取
    @Override
    public void invoke(DictEeVo dictEeVO, AnalysisContext analysisContext) {
        // 调用方法添加数据库
        BlogDict dict = new BlogDict();
        BeanUtils.copyProperties(dictEeVO,dict);
        dictMapper.addBlogDict(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
